﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;

namespace BLL
{
  public class VisitedBLL
  {
    public void Save(int total)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        if (data.Visiteds.Count() == 0)
        {
          Visited obj = new Visited();
          obj.Total = total;
          obj.Date = DateTime.Now;
          data.Visiteds.InsertOnSubmit(obj);
          data.SubmitChanges();
        }
        else
        {
          Visited obj = data.Visiteds.First();
          obj.Total = total;
          data.SubmitChanges();
        }
      }
    }
    public int GetValue()
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        Visited obj = data.Visiteds.FirstOrDefault();
        if (obj != null)
          return obj.Total;
        else return 0;
      }
    }
  }
}
